package com.zy.mc_module.base;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import java.util.ArrayList;

/**
 * Created on 18/10/24
 * FragmentStatePagerAdapter是直接销毁fragment，而不是复用
 */
public class BaseFStatePagerAdapter extends FragmentStatePagerAdapter {
    private ArrayList<Fragment> fragments;
    private ArrayList<String> titles;

    public BaseFStatePagerAdapter(FragmentManager fm, ArrayList<Fragment> lists) {
        super(fm);
        fragments = lists;
        titles = new ArrayList<>();
    }

    public BaseFStatePagerAdapter(FragmentManager fm, ArrayList<Fragment> lists, ArrayList<String> titles) {
        super(fm);
        fragments = lists;
        this.titles = titles;
    }

    @Override
    public Fragment getItem(int i) {
        return fragments.get(i);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        if (position <= titles.size() - 1) {
            return titles.get(position);
        } else {
            return "";
        }
    }
}
